package com.sfx.算法专题.双指针.同向双指针.普通双指针;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-07-18
 * Time: 12:27
 */
public class Code_4_removeElement {
    static class Solution {
        public int removeElement(int[] nums, int val) {
            int cur = 0;//寻找不删除的元素
            int dest = 0;//dest以前全是不能被移除的元素
            int n = nums.length;
            while(cur < n) {
                if(nums[cur] == val) {
                    cur ++;
                }else {
                    //找到不能被删除的元素,赋值给dest
                    nums[dest++] = nums[cur++];
                }
            }
            return dest;
        }
    }
}